package com.xbh.validator;

import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.validate.Validator;
import com.xbh.zzzTest.RetTest;

/**
 * @LoginValidator: 登录校验器
 * @author: ZBoHang
 * @time: 2021/8/5 13:14
 */
public class LoginValidator extends Validator {
    private final String errorKey = "msg";

    @Override
    protected void validate(Controller controller) {
        setRet(RetTest.me.setFail());
        setShortCircuit(true);
        String userName = controller.getPara("userName");
        String userPass = controller.getPara("userPass");
        if (StrKit.isBlank(userName)) {
            addError(errorKey, "用户名不能为空!");
        }
        if (StrKit.isBlank(userPass)) {
            addError(errorKey, "密码不能为空");
        }
    }

    @Override
    protected void handleError(Controller controller) {
        controller.renderJson(getRet());
    }
}
